package com.enhe.gck.fg;

import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.communal.PublicReturn;
import com.enhe.gck.item.GoodsTypeHWANE18600Item;
import com.enhe.gck.pojo.SalesPlan;
import com.kuangkie.carbon.common.AggregateVO;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.RecordQueryProConJunctionFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.fg.FuncGroupContext;
import com.kuangkie.carbon.fg.ImproveResultFactory;
import com.kuangkie.carbon.fg.SecondRoundImproveFuncGroup;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.CarbonRelationType; //关系类型Code
import com.enhe.gck.item.SalesPlanHWANE19367Item; // 模型属性Code

@Slf4j
@Repository(value = "hwane19367366042330866425862")
public class SalesPlanHWANE19367BNB implements SecondRoundImproveFuncGroup{
	
	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
		SalesPlan info =proRecord.getBean(SalesPlan.class);

		if(isHave(info.getDate(),proRecord.getGuestRecordCode(CarbonRelationType.RR_销售计划_产品类型_产品类型))){
			PublicMethod.returnMessage(improveResultFactory, PublicReturn.SalesPlan_1);
			return ;
		}
	}

	/**
	 * 获取数据是否存在
	 */
	public static boolean isHave(String data,String rId) {
		boolean flag = false;
		RecordQueryProConJunctionFactory query=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.销售计划_xsjh).getProConJunctionFactory()
				.addEqual(SalesPlanHWANE19367Item.基本属性组_日期,data);
		query.getRelationCriterionFactory(CarbonBaseConstant.产品类型_cplx)
				.setInRelationTypes(CarbonRelationType.RR_销售计划_产品类型_产品类型)
				.setInGuestCodes(rId);
		AggregateVO aggregateVO = query.goBack().queryCount();
		if(aggregateVO!=null&&aggregateVO.getCount()>0){
			flag=true;
		}
		return flag;
	}
}
